package cn.edu.buaa.cnsatm.traffic_big_data_server.railway.controller;

import cn.edu.buaa.cnsatm.traffic_big_data_server.railway.model.RailwayStatusModel;
import cn.edu.buaa.cnsatm.traffic_big_data_server.railway.service.RailwayStatusService;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLException;
import java.util.ArrayList;

@RestController
public class RailwayStatusController {
    @Autowired
    private RailwayStatusService railwayStatusService;
    //接收请求返回数据
    @RequestMapping(value = "/railwayStatus")
    public String getRwStatus(
            @RequestParam(value = "top_num", defaultValue = "8", required = true) Integer itemNum
    ) {
        ArrayList<RailwayStatusModel> statusList= null;
        try {
            return JSONObject.toJSONString(railwayStatusService.getStatusList(itemNum),SerializerFeature.WriteMapNullValue);
        } catch (SQLException e) {
            return JSONObject.toJSONString(new RailwayStatusModel(), SerializerFeature.WriteMapNullValue);
        }
    }
    @RequestMapping(value = "/railwayWeatherEffect")
    public String webGetTopKWeatherEffect(
            @RequestParam(value = "top_num", defaultValue = "8", required = true) int k
    ) throws SQLException {
        /**
         * @author LX
         * @description 铁路天气影响
         * @date 2019-11-05
         */
        return railwayStatusService.getTopKRailwayWeatherEffect(k);
    }
}


